home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
edump.arc
/
EDUMP.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-12-01
|
6KB
|
188 lines
PROGRAM Edump;
{
EDUMP 1.0
11/30/85
EDUMP displays a HEX dump of a file. In addition, an EYEreadable dump
is also displayed. An option of the program is display the file in
either ASCII or EBCDIC.
To execute EDUMP enter EDUMP filename /switches There are 4 switches;
/C/P/E/A. Either /C or /P may be enter to dump the file on the console
or printer.
These 2 options are mutually exclusive. The /A option is
the default and the file will be dumped in ASCII. If the /E option is
chosen, the file will be dumped as though it were EBCDIC.
An include file has been used to define the translate table. There are 2
arrays in the include file. They are named ETOA and ATOE for EBCDIC to
ASCII and ASCII to EBCDIC respectively. In ETOA a corresponding ASCII
character is chosen for each EBCDIC character where ever possible.
Since their are 256 valid EBCDIC codes, not every character has an
approriate ASCII equivalent. The same is true for ATOE. In addition,
ATOE has 256 entries even through only 128 ASCII codes are defined. The
first 128 entries are duplicated. This essentially treats the last 128
characters like the first 128, only the high order bit is set with
parity.
The table was built using the IBM System/370 Reference Summary. IBM form
number GX20-1850. You are welcome to build your own table. All that is
needed it to alter XLATE.INC and recompile the program.
The program is written for the IBM PC in Turbo Pascal. Version 3 of the
compiler is needed recompile.
Daryl Coulthart
532 Lake Bayview Court
Shoreview MN 55126
(612) 483-1489
}
CONST bufnumber = 32;
buflength =8191;
{$I XLATE.INC}
TYPE STRING14=STRING[14];
VAR SOURCE,DESTINATION : FILE;
CH:CHAR;
outfile: TEXT;
FILENAME:STRING14;
BUFFER : ARRAY[0..buflength] of BYTE;
SCRNNO,i,K,L,bufno,NOOFRECSTOREAD,REMAINING:INTEGER;
mode : CHAR;
FUNCTION EXIST(FILENAME:STRING14):BOOLEAN;
VAR INFILE : FILE;
BEGIN
ASSIGN(INFILE,FILENAME);
{$I-*}
RESET (INFILE);
{ $I+*}
EXIST := (IORESULT=0);
END;
PROCEDURE HEX(HB:BYTE; VAR LB,RB:CHAR);
CONST CHS : ARRAY[0..15] OF CHAR
= ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
BEGIN
LB := CHS[HB DIV 16];
RB := CHS[HB MOD 16];
END;
PROCEDURE displaybuffer;
VAR T,I,J,N,M,OFFSET,LI:INTEGER;
LL,LR:BYTE;
LB,RB:CHAR;
BEGIN
CLRSCR;
WRITELN(outfile,'Edump 1.0 ':15,'FILE NAME : ',FILENAME,
' PART : ', K+1+bufno*(bufnumber DIV 2), ' OF ',SCRNNO);
WRITELN(outfile);
if mode = 'E' then
WRITELN(outfile,'OFFSET',' ':24, 'HEXIDECIMAL',' ':24,'EBCDIC');
if mode = 'A' then
WRITELN(outfile,'OFFSET',' ':24, 'HEXIDECIMAL',' ':25,'ASCII');
WRITELN(outfile,'------ ',
' -0--1--2--3--4--5--6--7--8--9--A--B--C--D--E--F 0123456789ABCDEF');
WRITELN(outfile);
FOR I := 0 TO 15 DO
BEGIN
L := L + 16;
LI := L DIV 256; LL := LI;
LR := L MOD 256;
OFFSET := bufno*256 + L;
HEX(LL,LB,RB); WRITE(OUTFILE,' ',LB,RB);
HEX(LR,LB,RB); WRITE(OUTFILE,LB,RB,' ');
{HEX DUMP}
FOR J := 0 TO 15 DO
BEGIN
N := OFFSET + J;
HEX(ORD(BUFFER[N]),LB,RB); WRITE(OUTFILE,LB,RB,' ');
END;
WRITE(outfile,' ');
{ASCII / EBCDIC DUMP}
FOR J := 0 TO 15 DO
BEGIN
N := OFFSET + J;
T := ORD(BUFFER[N]);
if mode = 'E' then M := ETOA[T]
else M := T;
IF M > 127 THEN M := M - 128;
IF (M > 31) AND (M < 127) THEN
WRITE(outfile,chr(M))
ELSE
WRITE(outfile, '.'); {UNDISPLAYABLE CHARACTERS}
END;
WRITELN(outfile);
END;
END;
BEGIN
if ParamCount = 2 then
begin
FILENAME := PARAMSTR(1);
IF EXIST(FILENAME) THEN
BEGIN
ASSIGN(SOURCE,FILENAME);
RESET(SOURCE);
END
ELSE
BEGIN
WRITELN('INVALID FILE NAME, ENTER EDUMP WITH NO PARAMETERS FOR HELP.');
HALT;
END;
IF POS('C',PARAMSTR(2)) > 0 THEN ASSIGN(OUTFILE,'CON:')
else IF POS('c',PARAMSTR(2)) > 0 THEN ASSIGN(OUTFILE,'CON:')
else IF POS('P',PARAMSTR(2)) > 0 THEN ASSIGN(OUTFILE,'LST:')
else IF POS('p',PARAMSTR(2)) > 0 THEN ASSIGN(OUTFILE,'LST:')
else ASSIGN(OUTFILE,'CON:');
IF POS('a',PARAMSTR(2)) > 0 THEN MODE := 'A'
ELSE IF POS('A',PARAMSTR(2)) > 0 THEN MODE := 'A'
ELSE IF POS('E',PARAMSTR(2)) > 0 THEN MODE := 'E'
ELSE IF POS('e',PARAMSTR(2)) > 0 THEN MODE := 'E'
ELSE MODE := 'A';
END
ELSE BEGIN
WRITELN('Usage, EDUMP FILENAME.EXT /C/P/A/E');
WRITELN(' ');
WRITELN('Where /C directs output to console.');
WRITELN(' /P directs output to printer.');
WRITELN(' /A indicates input file is to be interpreted as ASCII.');
WRITELN(' /E indicates input file is to be interpreted as EBCDIC.');
WRITELN(' /C & /P are mutually exclusive, and /A & /E are also.');
HALT;
END;
REMAINING := FILESIZE(SOURCE);
if odd(remaining) then SCRNNO := (REMAINING DIV 2) + 1
else SCRNNO := REMAINING DIV 2;
bufno := 0; l := 0 - 16;
WHILE REMAINING > 0 DO
BEGIN
IF bufnumber <= REMAINING THEN NOOFRECSTOREAD := bufnumber
ELSE NOOFRECSTOREAD := REMAINING;
BLOCKREAD(SOURCE,BUFFER,NOOFRECSTOREAD);
FOR K := 0 TO ((NOOFRECSTOREAD-1) DIV 2) DO
BEGIN
displaybuffer;
WRITELN;
WRITE( ' ':6,'Press <ESC> to exit or return to continue.');
READ(KBD,CH);
IF ORD(CH)=27 THEN HALT;
END;
bufno := bufno + 1;
REMAINING := REMAINING - NOOFRECSTOREAD;
END;
END.